SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO



--Procedimiento wldiccionario_campos
CREATE   PROCEDURE dbo.wldiccionario_campos
@desde_campo _nombre,
@hasta_campo _nombre

AS

select
	tipos.cd_tipo,
	tipos.de_tipo,
	cam.nm_campo,
	cam.de_campo,
	c.name as nm_tipo,
	b.length as va_longitud,
	b.scale as ca_decimales
from
	wad_campos cam
	join (select 'ca' as cd_tipo, 'Cantidad' as de_tipo
	union
	select 'cd', 'Código'
	union
	select 'de', 'Descripción'
	union
	select 'fe', 'Fecha'
	union
	select 'hr', 'Hora'
	union
	select 'im', 'Importe'
	union
	select 'nm', 'Nombre'
	union
	select 'nu', 'Número'
	union
	select 'st', 'Estado'
	union
	select 'tp', 'Tipo'
	union
	select 'po', 'Porcentaje'
	union
	select 'va', 'Valor') tipos  on tipos.cd_tipo = lower(left(cam.nm_campo,2))
left join 
	(select col.name, max(col.usertype) as usertype, max(col.length) as length, max(col.scale) as scale from syscolumns col group by col.name) b on b.name = lower(cam.nm_campo)
left join
	(select ty.usertype, max(ty.name) as name from systypes ty group by ty.usertype) c on b.usertype = c.usertype
where
	cam.nm_campo between @desde_campo and @hasta_campo
order by
	cam.nm_campo

GO
